<?php

/**
 * This is the model class for table "product".
 *
 * The followings are the available columns in table 'product':
 * @property integer $pro_id
 * @property string $pro_code
 * @property string $pro_name
 * @property integer $pro_cat_id
 * @property integer $pro_price
 * @property string $pro_origin
 * @property string $pro_gua
 * @property string $pro_pic
 * @property string $pro_pic_1
 * @property string $pro_pic_2
 * @property integer $pro_num_sold
 * @property string $pro_des
 * @property string $pro_content
 * @property integer $pro_date
 */
class Product extends CActiveRecord
{
	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'product';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('pro_name, pro_cat_id, pro_price, pro_origin, pro_gua, pro_pic, pro_pic_1, pro_pic_2, pro_des, pro_content, pro_date', 'required'),
			array('pro_cat_id, pro_price, pro_num_sold, pro_date', 'numerical', 'integerOnly'=>true),
			array('pro_code', 'length', 'max'=>20),
			array('pro_name, pro_pic, pro_pic_1, pro_pic_2', 'length', 'max'=>255),
			array('pro_origin, pro_gua', 'length', 'max'=>100),
			// The following rule is used by search().
			// @todo Please remove those attributes that should not be searched.
			array('pro_id, pro_code, pro_name, pro_cat_id, pro_price, pro_origin, pro_gua, pro_pic, pro_pic_1, pro_pic_2, pro_num_sold, pro_des, pro_content, pro_date', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'pro_id' => 'Pro',
			'pro_code' => 'Pro Code',
			'pro_name' => 'Pro Name',
			'pro_cat_id' => 'Pro Cat',
			'pro_price' => 'Pro Price',
			'pro_origin' => 'Pro Origin',
			'pro_gua' => 'Pro Gua',
			'pro_pic' => 'Pro Pic',
			'pro_pic_1' => 'Pro Pic 1',
			'pro_pic_2' => 'Pro Pic 2',
			'pro_num_sold' => 'Pro Num Sold',
			'pro_des' => 'Pro Des',
			'pro_content' => 'Pro Content',
			'pro_date' => 'Pro Date',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 *
	 * Typical usecase:
	 * - Initialize the model fields with values from filter form.
	 * - Execute this method to get CActiveDataProvider instance which will filter
	 * models according to data in model fields.
	 * - Pass data provider to CGridView, CListView or any similar widget.
	 *
	 * @return CActiveDataProvider the data provider that can return the models
	 * based on the search/filter conditions.
	 */
	public function search()
	{
		// @todo Please modify the following code to remove attributes that should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('pro_id',$this->pro_id);
		$criteria->compare('pro_code',$this->pro_code,true);
		$criteria->compare('pro_name',$this->pro_name,true);
		$criteria->compare('pro_cat_id',$this->pro_cat_id);
		$criteria->compare('pro_price',$this->pro_price);
		$criteria->compare('pro_origin',$this->pro_origin,true);
		$criteria->compare('pro_gua',$this->pro_gua,true);
		$criteria->compare('pro_pic',$this->pro_pic,true);
		$criteria->compare('pro_pic_1',$this->pro_pic_1,true);
		$criteria->compare('pro_pic_2',$this->pro_pic_2,true);
		$criteria->compare('pro_num_sold',$this->pro_num_sold);
		$criteria->compare('pro_des',$this->pro_des,true);
		$criteria->compare('pro_content',$this->pro_content,true);
		$criteria->compare('pro_date',$this->pro_date);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}

	/**
	 * Returns the static model of the specified AR class.
	 * Please note that you should have this exact method in all your CActiveRecord descendants!
	 * @param string $className active record class name.
	 * @return Product the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
}
